import type { Request, Response } from 'express';

const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

// 仪表盘统计数据 Mock
export default {
  'GET /api/dashboard/stats': async (_req: Request, res: Response) => {
    await waitTime(500);
    res.send({
      success: true,
      data: {
        totalUsers: 1250,
        todayVisits: 832,
        totalOrders: 567,
        revenue: 45678,
        charts: {
          visits: [
            { date: '2024-01-01', value: 120 },
            { date: '2024-01-02', value: 132 },
            { date: '2024-01-03', value: 101 },
            { date: '2024-01-04', value: 134 },
            { date: '2024-01-05', value: 90 },
            { date: '2024-01-06', value: 230 },
            { date: '2024-01-07', value: 210 },
          ],
          orders: [
            { date: '2024-01-01', value: 85 },
            { date: '2024-01-02', value: 92 },
            { date: '2024-01-03', value: 78 },
            { date: '2024-01-04', value: 104 },
            { date: '2024-01-05', value: 67 },
            { date: '2024-01-06', value: 156 },
            { date: '2024-01-07', value: 143 },
          ],
        }
      }
    });
  },
  
  'GET /api/dashboard/recent-activities': async (_req: Request, res: Response) => {
    await waitTime(300);
    res.send({
      success: true,
      data: [
        { id: 1, user: '张三', action: '创建了新订单', time: '5分钟前', avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png' },
        { id: 2, user: '李四', action: '更新了用户资料', time: '15分钟前', avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png' },
        { id: 3, user: '王五', action: '删除了过期数据', time: '1小时前', avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png' },
        { id: 4, user: '赵六', action: '发布了新公告', time: '2小时前', avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png' },
      ]
    });
  }
};
